package com.lixianbiao.validation.processor;


import com.lixianbiao.validation.annotation.StringPattern;

import java.lang.annotation.Annotation;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author lixianbiao
 * @since 2024/06/22 09:41
 */
public class PatternProcessor implements Processor {
    @Override
    public boolean process(Annotation annotation, Object object) {
        if(annotation instanceof StringPattern  && object instanceof String ){
            StringPattern patternAnnotation = (StringPattern) annotation;
            String str = (String)object;
            Pattern pattern = Pattern.compile(patternAnnotation.value());
            Matcher matcher = pattern.matcher(str);
            return matcher.find();
        }else {
            throw new IllegalArgumentException();
        }
    }
}